package com.joven.shelltest.utils.seondkill;

import com.joven.shelltest.model.SuccessKilled;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @Author wzj
 * @Date 2023-08-15 10:23
 **/
@Slf4j
//@Component
public class TaskRunner implements ApplicationRunner {

//    @Autowired
//    private SecondKillService seckillService;

    @Override
    public void run(ApplicationArguments args) {
        new Thread(() -> {
            log.info("队列启动成功");
            while(true){
                try {
                    // 进程内队列
                    SuccessKilled kill = SecondKillQueue.getSkillQueue().consume();
                    if(kill != null){
                        //调用带@ServiceLock的处理方法
//                        Result result = seckillService.startSecondKillByAop(kill.getSecKillId(), kill.getUserId());
//                        if(result != null && result.equals(Result.ok(SecondKillStateEnum.SUCCESS))){
//                            log.info("TaskRunner,result:{}",result);
//                            log.info("TaskRunner从消息队列取出用户，用户:{}{}",kill.getUserId(),"秒杀成功");
//                        }
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
